package com.sz.admin.ai.util;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component

public class TimeAspect {
	
	@Pointcut(value = "@annotation(com.ruoyi.web.controller.ai.util.LogAspect))")
	public void pointCut(){
	
	}
	
	@Around(value =  "pointCut()")
	public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
		
		// 获取方法签名
		String methodName = proceedingJoinPoint.getSignature().toShortString();
		
		// 打印入参
		Object[] args = proceedingJoinPoint.getArgs();
		log.info("方法 {} 入参: {}", methodName, JSON.toJSONString(args));
		
		// 执行目标方法
		Object result = proceedingJoinPoint.proceed();
		
		// 打印出参
		log.info("方法 {} 出参: {}", methodName, JSON.toJSONString(result));
		
		return result;
	}
	
	// // 前处理
	// @Before(value =  "pointCut()")
	// public void before(JoinPoint JoinPoint) throws Throwable {
	// 	System.out.println("前处理");
	// }
	//
	// // 后处理
	// @After(value = "pointCut()")
	// public void after(JoinPoint JoinPoint) throws Throwable {
	// 	System.out.println("后处理");
	// }
	//
	// // 返回后处理
	// @AfterReturning(value = "pointCut()")
	// public void afterReturning(JoinPoint JoinPoint) throws Throwable {
	// 	System.out.println("返回后处理");
	// }
	//
	// // 异常处理
	// @AfterThrowing(value = "pointCut()")
	// public void afterThrowing(JoinPoint JoinPoint) throws Throwable {
	// 	System.out.println("异常处理");
	// }
}
